package com.ctgu.server.controller;


import com.ctgu.server.dao.dto.AttendanceGroupDto;
import com.ctgu.server.dao.entity.AttendanceGroup;
import com.ctgu.server.dao.vo.Result;
import com.ctgu.server.service.AttendanceGroupService;
import com.ctgu.server.service.AttendanceGroupUserService;
import com.ctgu.server.service.impl.UserServiceImpl;
import com.ctgu.server.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ctgu
 * @since 2023-06-13
 */
@RestController
@RequestMapping("/server/attendanceGroup")
@Api(tags = "打卡信息操作接口")
public class AttendanceGroupController {
    @Autowired
    private UserServiceImpl userService;
    @Autowired
    private AttendanceGroupService attendanceGroupService;
    @PostMapping("/create")
    @ApiOperation(notes = "新增考勤组",value = "新增考勤组")
    public Result createAttendanceGroup(@RequestBody AttendanceGroup attendanceGroup){
        if(attendanceGroup.getUserId()==null||userService.selectUser(attendanceGroup.getUserId())==null){
            return ResultUtil.error("参数userID错误");
        }
       //创建一个时间工具类效验时间的合法性
        attendanceGroupService.save(attendanceGroup);
        return ResultUtil.success();
    }

    @PostMapping("/clock")
    @ApiOperation(notes = "新增默认打卡",value = "新增默认打卡")

    public Result createClockGroup(@RequestBody AttendanceGroupDto attendanceGroupDto){

        return attendanceGroupService.createClockGroup(attendanceGroupDto);
    }
}

